package org.chen.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.chen.common.model.DailyStats;
import org.chen.common.page.CommonPage;
import org.chen.common.request.PageParamRequest;
import org.chen.common.request.RejectRefundRequest;
import org.chen.common.response.CommonResult;
import org.chen.common.response.OrderTravelDetailResponse;
import org.chen.common.vo.MyRecord;
import org.chen.service.DailyStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController("AdminController")
@RequestMapping("api/admin")
@Tag(name = "管理员 -- 页面请求")
public class AdminController {
    @Autowired
    private DailyStatsService dailyStatsService;

    /**
     * 每日数据统计(旅游)
     * @return 每日数据
     */
    @Operation(summary = "每日数据")
    @RequestMapping(value = "/daily-stat", method = RequestMethod.GET)
    public CommonResult<DailyStats> orderDailyStat() {
        return CommonResult.success(dailyStatsService.getDailyStats());
    }

    /**
     * 批准退款(旅游)
     * @return 状态
     */
    @Operation(summary = "批准退款")
    @RequestMapping(value = "/approve-refund/{id}&{orderId}", method = RequestMethod.POST)
    public CommonResult<Boolean> approveRefund(@PathVariable("id") Long id, @PathVariable("orderId") String orderId) {
        return CommonResult.success(dailyStatsService.approveRefund(id,orderId));
    }

    /**
     * 拒绝退款(旅游)
     * @return 状态
     */
    @Operation(summary = "拒绝退款")
    @RequestMapping(value = "/reject-refund/{id}&{orderId}", method = RequestMethod.POST)
    public CommonResult<Boolean> rejectRefund(@PathVariable("id") Long id,
                                              @PathVariable("orderId") String orderId,
                                              @RequestBody RejectRefundRequest request) {
        return CommonResult.success(dailyStatsService.rejectRefund(id,orderId,request));
    }

    /**
     * 获取退款订单(旅游)
     * @return 订单退款列表
     */
    @Operation(summary = "订单退款列表")
    @RequestMapping(value = "/refund-orders", method = RequestMethod.GET)
    @Parameter(name = "type", description = "退款等级|-1=审核中,-2=退款中,-3=已退款", required = true, in = ParameterIn.QUERY)
    @Parameter(name = "orderId", description = "订单号||支付单号", in = ParameterIn.QUERY)
    public CommonResult<CommonPage<OrderTravelDetailResponse>> refundOrders(@RequestParam(name = "type") Integer type,
                                                                            @RequestParam(name = "orderId") String orderId,
                                                                            @ModelAttribute PageParamRequest pageRequest) {
        return CommonResult.success(dailyStatsService.getRefundOrders(type,orderId,pageRequest));
    }

    /**
     * 获取订单列表(旅游)
     * @return 订单退款列表
     */
    @Operation(summary = "订单列表")
    @RequestMapping(value = "/orders", method = RequestMethod.GET)
    @Parameter(name = "type", description = "订单状态|0=未支付,1=待使用,2=已完成,3=已取消,-1=退款审核中,-2=退款中,-3=已退款,-5=退款失败,-4=全部", required = true, in = ParameterIn.QUERY)
    @Parameter(name = "orderId", description = "订单号||支付单号", in = ParameterIn.QUERY)
    public CommonResult<CommonPage<OrderTravelDetailResponse>> orders(@RequestParam(name = "type") Integer type,
                                                                      @RequestParam(name = "orderId") String orderId,
                                                                            @ModelAttribute PageParamRequest pageRequest) {
        return CommonResult.success(dailyStatsService.getOrders(type,orderId,pageRequest));
    }
}
